package com.smarthome.web.property.controller.propertymanager;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.housemanager.ResidenceManagerService;
import com.smarthome.core.propertymanager.PropertyMoneyService;
import com.smarthome.domain.bean.ShResidence;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.web.property.utils.UserHolder;

/**
 * 费用管理
 * 
 * @author hgj
 * 
 */
@Controller
@RequestMapping("/propertyMoneyController")
public class PropertyMoneyController {

	@Resource
	private ResidenceManagerService residenceManagerService;
	@Resource
	private PropertyMoneyService propertyMoneyService;

	@RequestMapping("/views")
	public String views(HttpServletRequest request) {
		ShResidence shResidence = new ShResidence();
		if (!UserHolder.isSuperResidence()) {
			shResidence.setId(UserHolder.getCurrentResidenceId());
		}
		request.setAttribute("residences",
				residenceManagerService.queryShResidences(shResidence));
		return "/propertyManager/propertyMoney";
	}

	/**
	 * 获取选择门牌号对应的物管费
	 * 
	 * @param ph
	 * @param numId
	 * @return
	 */
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(PageHelper ph, Long numId) {
		DataGrid dataGrid;
		if (numId != null) {
			dataGrid = propertyMoneyService.dataGrid(ph, numId);
		} else {
			dataGrid = new DataGrid();
		}
		return dataGrid;
	}

	/**
	 * 根据小区ID计算该小区下所有门牌住户的物管费
	 * 
	 * @param residenId
	 * @return
	 */
	@RequestMapping("/doMoney")
	@ResponseBody
	public String doMoney(Long residenId) {
		return propertyMoneyService.doMoney(residenId);
	}
}
